package com.UBC417.termproject.Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.UBC417.termproject.Data.Bid;
import com.UBC417.termproject.Data.Buyer;
import com.UBC417.termproject.Data.User;
import com.google.gson.Gson;

@SuppressWarnings("serial")
public class MonitorAuctionServlet extends HttpServlet{
	private static final Logger log = Logger.getLogger(SubscribeServlet.class.getName());

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {
		// Get parameters		
		String auctionId = req.getParameter("auctionId2");
		
		HttpSession session = req.getSession();

		
		log.info("auctionId: "+ auctionId);
		
		List<Bid> bids = User.MonitorAuction(auctionId);
		
		resp.setContentType("text/plain");
	    resp.setCharacterEncoding("UTF-8");
	    resp.getWriter().write(new Gson().toJson(bids));
	    
	    
//		PrintWriter out= resp.getWriter();
//		resp.setContentType("text/html");
//		out.println("<html>");
//        out.println("<head><title>Monitor Auction</title></head>");
//        out.println("<body>");
//		if (bids.size()>0){
//			out.println("<table border='1'>");
//			out.println("<tr>");
//			out.println("<td>Item Name</td>");
//			out.println("<td>Buyer ID</td>");
//			out.println("<td>Date</td>");
//			out.println("<td>Price</td>");
//			out.println("</tr>");
//			for (Bid b : bids){
//				out.println("<tr>");
//				out.println("<td>"+b.getItemName()+"</td>");
//				out.println("<td>"+b.getUserId()+"</td>");
//				out.println("<td>"+b.getDateCreated()+"</td>");
//				out.println("<td>"+b.getPrice()+"</td>");
//			}
//			out.println("</table>");
//		}
//		else{
//			out.println("NO BIDS!<br>");
//		}
//		out.println("<a HREF='javascript:history.back()'>Back</a>");
//		out.println("</body></html>");
		
		
		
		
	}

}
